import java.util.*;

public class Leet1654 {
    public static void main(String[] args) {
        Leet1654 l = new Leet1654();
        System.out.println(l.minimumJumps(new int[]{162,118,178,152,167,100,40,74,199,186,26,73,200,127,30,124,193,84,184,36,103,149,153,9,54,154,133,95,45,198,79,157,64,122,59,71,48,177,82,35,14,176,16,108,111,6,168,31,134,164,136,72,98},29,98,80));
    }
    public int minimumJumps(int[] forbidden, int a, int b, int x) {
        Deque<int[]> deque = new ArrayDeque<>();
        Set<Integer> set = new HashSet<>();
        Set<Integer> last = new HashSet<>();
        boolean flag = false;
        for (int i : forbidden)
            set.add(i);
        deque.add(new int[]{0,1});
        boolean no = false;
        int num = 0;
        while (!deque.isEmpty()){
            num++;
            int[] temp = deque.poll();
            int aa = temp[0]+a;
            int bb = temp[0]-b;
            if (aa==x||bb==x){
                flag = true;
                break;
            }
            if (!set.contains(bb)&&!last.contains(bb)&&bb>=0&&temp[1]!=0){
                deque.add(new int[]{aa,0});
                last.add(aa);
            }
            if (!set.contains(aa)&&!last.contains(aa)&&aa<4000){
                deque.add(new int[]{bb,1});
                last.add(aa); }
        }
        return flag?num:-1;
    }
}
